/**
 * 公共脚本
 * @author nowind
 * @date 15/3/17 12:18
 */

var omsUtil = {
    docHeight: function() { //网页高度
        return $(document).height();
    },
    winWidth: function() {  //窗口宽度
        return document.documentElement.clientWidth;
    },
    winHeight: function() { //窗口高度
        return document.documentElement.clientHeight;
    },

    //是否数字，decimal允许小数
    isNumber: function(value, allDecimal){
        allDecimal = omsUtil.isNull(allDecimal) ? false : allDecimal;
        var reg = allDecimal ? /^[0-9]+.?[0-9]*$/ : /^[0-9]+$/;
        return reg.test(value);
    },
    //是否为空
    isNull: function(value){
        return (typeof value == "undefined" || value == null) ? true : false;
    },
    //是否不为空
    isNotNull: function(value){
        return (typeof value == "undefined" || value == null) ? false : true;
    },
    //是否是否为空或空字符串
    isEmptyNull: function(str){
        return (typeof str == "undefined" || str == null || str == "") ? true : false;
    },
    //手机号格式校验
    isMobile: function(mobile){
        if(!(/^1[3|4|5|7|8][0-9]\d{8}$/.test(mobile.trim()))){ return false; } else { return true; }
    },
    bindStatus: function(type, code){
      switch (type) {
          case "login": return constant.MESSAGE.LOGIN[code]; break;
          default:break;
      }
    },
    direct: function(url,timeout){
        if(typeof timeout == "undefined" ){ timeout = 0; }
        setTimeout(function(){
            if(typeof url == "undefined"){url=location.href;}
            window.location = url;
        },timeout);
    },
    back: function(isRefresh){
        if(isRefresh) { var url = document.referrer; omsUtil.direct(url); }
        else { history.back(); }
    }
};


//扩展Date的format方法
Date.prototype.format = function (format) {
    var o = {
        "M+": this.getMonth() + 1,
        "d+": this.getDate(),
        "h+": this.getHours(),
        "m+": this.getMinutes(),
        "s+": this.getSeconds(),
        "q+": Math.floor((this.getMonth() + 3) / 3),
        "S": this.getMilliseconds()
    };
    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;
};
var date = {
    /**
     *转换日期对象为日期字符串
     * @param date 日期对象
     * @param isFull 是否为完整的日期数据,
     *               为true时, 格式如"2000-03-05 01:05:04"
     *               为false时, 格式如 "2000-03-05"
     * @return 符合要求的日期字符串
     */
    formatDateSmp: function (date, isFull) {
        var pattern = "";
        if (isFull == true || isFull == undefined) {
            pattern = "yyyy-MM-dd hh:mm:ss";
        } else {
            pattern = "yyyy-MM-dd";
        }
        return date.formatDate(date, pattern);
    },
    /**
     *转换当前日期对象为日期字符串
     * @param date 日期对象
     * @param isFull 是否为完整的日期数据,
     *               为true时, 格式如"2000-03-05 01:05:04"
     *               为false时, 格式如 "2000-03-05"
     * @return 符合要求的日期字符串
     */
    formaNowDateSmp: function (isFull) {
        return date.formatDateSmp(new Date(), isFull);
    },
    /**
     *转换long值为日期字符串
     * @param l long值
     * @param isFull 是否为完整的日期数据,
     *               为true时, 格式如"2000-03-05 01:05:04"
     *               为false时, 格式如 "2000-03-05"
     * @return 符合要求的日期字符串
     */

    formatDateByLongSmp: function(l, isFull) {
        return date.formatDateSmp(new Date(l), isFull);
    },
    /**
     *转换long值为日期字符串
     * @param l long值
     * @param pattern 格式字符串,例如：yyyy-MM-dd hh:mm:ss
     * @return 符合要求的日期字符串
     */
    formatDateByLong: function (l, pattern) {
        return date.formatDate(new Date(l), pattern);
    },
    /**
     *转换日期对象为日期字符串
     * @param l long值
     * @param pattern 格式字符串,例如：yyyy-MM-dd hh:mm:ss
     * @return 符合要求的日期字符串
     */
    formatDate: function (date2, pattern) {
        if (date2 == undefined) {
            date2 = new Date();
        }
        if (pattern == undefined) {
            pattern = "yyyy-MM-dd hh:mm:ss";
        }
        return date2.format(pattern);
    },
    //取得时长(秒)的描述性文本(到小时)，如43:30'13''
    descDuration: function (duration) {
        var desc = "";
        var hour = Math.floor(duration / (60 * 60));
        if (duration > 60 * 60) {
            desc += (hour + ":");
            duration = duration - 60 * 60 * hour;
        }
        if (hour > 0 || duration > 60) {
            var minute = Math.floor(duration / 60);
            desc += (minute + "'");
            duration = duration - 60 * minute;
        }
        if(duration > 0 ) {
            desc += (duration + "''")
        }
        return desc;
    }
};



/**********对象扩展属性 begin**********/

//格式化为12,456.00，digit为小数位数，默认2位
Number.prototype.formatMoney = function(digit) {
    if(omsUtil.isEmptyNull(digit)) { digit = 2; }
    digit = digit > 0 && digit <= 10 ? digit : digit;
    var tmp = parseFloat((this + "").replace(/[^\d\.-]/g, "")).toFixed(digit) + "";
    var l = tmp.split(".")[0].split("").reverse(),
        r = tmp.split(".")[1];
    t = "";
    for(i = 0; i < l.length; i ++ ) { t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : ""); }
    return t.split("").reverse().join("") + "." + r;
};

Number.prototype.formatYuan = function() {
    return parseFloat(this) / 100;
};

//四舍五入，保留2位小数
Number.prototype.scale = function(digit) {
    var i = parseFloat(this);
    if(isNaN(i)) { i = 0.00; }
    var minus = '';
    if(i < 0) { minus = '-'; }
    i = Math.abs(i);
    i = parseInt((i + .005) * 100);
    i = i / 100;
    s = new String(i);
    if(s.indexOf('.') < 0) { s += '.00'; }
    if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
    s = minus + s;
    return s;
};
//四舍五入，最多保留1位小数
Number.prototype.scaleAuto = function() {
    var i = parseFloat(this);
    if(isNaN(i)) { i = 0; }
    var minus = '';
    if(i < 0) { minus = '-'; }
    i = Math.abs(i);
    i = parseInt((i + .05) * 10);
    i = i / 10;
    s = new String(i);
    s = minus + s;
    return s;
};

//计算文件大小
Number.prototype.size = function(){
    var tmpSize = this/1024;
    if( tmpSize <= 1024 ){return Math.round(tmpSize * 100)/100 + "Kb"; }else{ return Math.round(tmpSize / 1024 * 100)/100 + "Mb"; }
};

//计算页数
Number.prototype.page = function(pageSize){
    return this % pageSize ==0 ? this / pageSize: ( parseInt( this / pageSize ) + 1);
};


//类似C#的字符串format
String.prototype.format = function() {
    var args = arguments;
    return this.replace(/\{(\d+)\}/g, function(m,i){return args[i]; });
    //return this.replace(/\{(%s)\}/g, function(m,i){return args[i]; });
};

//计算字符串大小（1个全角等于2个半角）
String.prototype.charslength = function(){
    if(omsUtil.isEmptyNull(this)) { return 0; }
    var value = this.replace(/[^\x00-\xff]/g, "**");
    return Math.round( value.length/2 );
};

//字符串转化为数字
String.prototype.digit = function() {
    if(omsUtil.isEmptyNull(this)) { return 0; }
    else { return this * 1; }
};

//截取指定长度的字符串
String.prototype.cut = function(length){
    if(this.length <= length ) { return this; } else { return this.substr(0,length); }
};
//截取两头字符串 length长度限制，leaveLength两头截取长度
String.prototype.cutCenter = function(length, leaveLength) {
    if(length <= leaveLength * 2) { return this; }
    var strLength =  this.replace(/[^\x00-\xff]/g, "**").length;    //实际长度
    if(strLength < leaveLength * 2) { return this; }
    if(strLength <= length) { return this; } else {
        var strL = this.substr(0,Math.round(leaveLength/2));
        var indexR = this.length - Math.round(leaveLength/2);
        var strR = this.substr(indexR);

        return strL + ".." + strR;
    }
};

//清除字符串前后空白
String.prototype.trim = function(){
    if(omsUtil.isEmptyNull(this)){return "";}else{ return $.trim(this);}
};

//escape，编码后URI可访问
String.prototype.escape = function(){
    if(omsUtil.isEmptyNull(this)){return "";}
    return escape(this);
};

//unescape
String.prototype.unescape  = function(){
    if(omsUtil.isEmptyNull(this)){return "";}
    return unescape(this);
};

//encodeURIComponent，编码后URI不可访问
String.prototype.encode = function(){
    if(omsUtil.isEmptyNull(this)){return "";}
    return encodeURIComponent(this);
};

//decodeURIComponent
String.prototype.decode = function(){
    if(omsUtil.isEmptyNull(this)){return "";}
    return decodeURIComponent(this);
};

//自动为Url加上http://
String.prototype.addstrHttp = function(){
    if(this.indexOf("http://") == -1) {return "http://"+this; } else {	return this;}
};

//自动为Url移除http://
String.prototype.cutstrHttp = function(){
    if(this.indexOf("http://") != -1) {return this.substr(7); } else {	return this;}
};

//设置或取得带传值的Url内的参数
String.prototype.param = function(name, value){
    //http://www.myspoor.com.aspx?uid=2&title=abc
    var pos =  this.indexOf("&"+name+"=");
    pos = pos != -1 ? pos: this.indexOf("?"+name+"=");
    if(typeof value == "undefined"){	//读取
        if( pos == -1 ) {return "";};
        var request = this.substr( pos + name.length + 2 );
        return request.indexOf("&") == -1 ? request: request.substring (0, request.indexOf("&"));
    } else {	//设置并返回新的request
        if( pos == -1 ) {
            if( this.indexOf("?") == -1 )	//直接附加到url后面
                return this + "?" + name + "=" + value;
            else
                return this + "&" + name + "=" + value;
        } else {
            var request1 = this.substring(0, pos + name.length + 2 );
            var request2 = this.substr( pos + name.length + 2 );
            return request2.indexOf("&") == -1 ? (request1 + value): (request1 + value + request2.substr( request2.indexOf("&") ));
        }
    }	//if else end
};

//设置或取得Url重写过的Url内的参数，以-分割
String.prototype.param2 = function(index, value){	//index 0开始
    //http://www.myspoor.com/diqu/beijing/jingdian-list-1.aspx
    var pos =  this.indexOf("-");
    pos = pos != -1 ? pos: this.indexOf("-");
    if(typeof value == "undefined"){	//读取
        if( pos == -1 ) {return "";};
        var request = this.substring (0, this.lastIndexOf("."));  //http://www.myspoor.com/diqu/beijing/jingdian-list-1
        return request.split("-")[index+1];
    } else {	//设置并返回新的request
        var request = this.substring (0, this.lastIndexOf("."));
        var ext = this.substr(this.lastIndexOf("."));
        if( pos == -1 ) {	//直接附加到url后面
            return request + "-" + value + ext;
        } else {
            var arry =  request.split("-");
            arry[index+1] = value;
            var url = arry[0];
            for(var i=1;i<arry.length;i++){ url += "-"+arry[i];}
            return url + ext;
        }
    }	//if else end
};

/**********对象扩展属性 end**********/


/**********cookie begin**********/

var cookie = {

    //读取，未取到则返回空字符串,如果有多个值，使用index，从0开始
    get: function(name, index){
        var str =  cookie.base(name);
        if( str == null || typeof str == "undefined" || str.length == 0 ){ return ""; }
        str = str.decode();
        if( typeof index == "undefined" || index == -1 ) { return unescape(str); }
        else if( str.indexOf('&') != -1 && str.indexOf('=') != -1 ) {
            str = str.split("&")[index]; str = str.split("=")[1];
            return str;
        }
        return "";
    },

    //写入,多个value值请用;分割，expires单位秒
    set: function(name, value, expires) {
        value = value.encode();
        cookie.base(name, value,{path: "/", expires:expires});
    },

    //删除
    remove: function(name) {
        cookie.base(name,"",{path: "/", expires:-1});
    },

    //cookie读写
    base: function(name, value, options) {
        if (typeof value != 'undefined') {  //写入
            options = options || {};
            if (value == null) { value = ''; options.expires = -1; }
            value += "";
            var expires = '';
            if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
                var date;
                if (typeof options.expires == 'number') {
                    date = new Date();
                    date.setTime(date.getTime() + (options.expires * 60 * 60 * 1000));	//以秒计
                } else {
                    //date = options.expires;
                    date = -1;
                }
                expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
            }
            var path = options.path ? '; path=' + (options.path): '';
            var domain = options.domain ? '; domain=' + (options.domain): '';
            var secure = options.secure ? '; secure': '';
            if( value.indexOf('&')>0 && value.indexOf('=')>0 ){
                var str = "";  var items = value.split('&');
                for( var i=0;i<items.length;i++ ) { str += "&"+items[i].split('=')[0] + "=" + (items[i].split('=')[1]);  }
                value = str.length > 0 ? str.substr(1): str ;
            }
            else { value = value; }
            document.cookie = [name, '=', value, expires, path, domain, secure].join('');
        }
        else {  //读取
            var cookieValue = null;
            if (document.cookie && document.cookie != '') {
                var cookiesAll = document.cookie;
                var cookies = document.cookie.split(';');
                for (var i = 0; i < cookies.length; i++) {
                    var cookie = $.trim(cookies[i]);
                    if (cookie.substring(0, name.length + 1) == (name + '=')) {
                        cookieValue = cookie.substring(name.length + 1);	// decodeURIComponent(cookie.substring(name.length + 1));
                        break;
                    }
                }
            }
            return cookieValue;
        }
    }   //end base

};   //end cookie

/**********cookie end**********/


/**********dialog begin **********/
var dialog = {
    DIG_STYLE: { POP:1, MUI: 2, DOING: 3 },
    DIG_ALPHA: { BODY: 1, POP:1, MODEL: 0.85 },
    pdmodelSelecter: "#pdmodel",
    $pdmodel: null,
    dialogSelecter: "#dialog",
    $dialog: null,
    headerSelecter: "#digheader",
    $header: null,
    titleSelecter: "#digtitle",
    $title: null,
    bodySelecter: "#digbody",
    $body: null,
    doingSelecter: "#digdoing",
    $doing: null,
    popSelecter: "#digpop",
    $pop: null,
    mode: true,	        //是否模态
    style: 1,
    refresh: false,     //关闭后是否刷新当前页面
    digWidth: 0,        //对话框宽度
    digHeight: 0,       //对话框高度
    //title 标题  content 内容  doing（显示doing）  showHeader是否显示标题
    init: function(title, content, showHeader, options){	//初始化

        //参数处理
        title = typeof title == "undefined" ? false : title;
        content = typeof content == "undefined" ? false : content;
        showHeader = typeof showHeader == "undefined" ? false : showHeader;
        if(!omsUtil.isEmptyNull(options)) {
            if(!omsUtil.isEmptyNull(options.width)) { dialog.digWidth = options.width - 20; }  //减去边距
            if(!omsUtil.isEmptyNull(options.height)) { dialog.digHeight = options.height -20; }
        }
        //Dom初始化
        dialog.$pdmodel = $(dialog.pdmodelSelecter);
        dialog.$dialog = $(dialog.dialogSelecter);

        var dialogHtml = "";
        if(showHeader) {
        dialogHtml += "	<div id=\"digheader\" class=\"dig-header\">";
        dialogHtml += "		<label id=\"digtitle\" class=\"dig-title\"></label>";
        dialogHtml += "		<a onclick=\"dialog.close();\" class=\"icon dig-close\"></a>";
        dialogHtml += "	</div>";
        }
        dialogHtml += "	<div id=\"digbody\" class=\"dig-content\"></div>";
        dialogHtml += "	<div id=\"digdoing\" class=\"dig-content-doing\" style=\"display:none;\"></div>";
        dialogHtml += "	<div id=\"digpop\" class=\"dig-content-pop\" style=\"display:none;\"></div>";
        dialog.$dialog.html(dialogHtml);
        dialog.$dialog.css({"height": ""}).removeClass().addClass("ui-dialog");

        dialog.$header = $(dialog.headerSelecter);
        dialog.$title = $(dialog.titleSelecter);
        dialog.$body = $(dialog.bodySelecter);
        dialog.$doing = $(dialog.doingSelecter);
        dialog.$pop = $(dialog.popSelecter);

        dialog.$title.html(title);
        switch (dialog.style) { //选择显示方式
            case dialog.DIG_STYLE.MUI:
                dialog.$body.show().html(content);
                if(dialog.digWidth > 0) { dialog.$body.width(dialog.digWidth); }
                if(dialog.digHeight > 0) { dialog.$body.height(dialog.digHeight); }
                dialog.$pop.hide();
                dialog.$doing.hide();
                dialog.$dialog.css({"left":((zmnPage.winWidth - dialog.$dialog.width()) / 2), "top":((zmnPage.winHeight - dialog.$dialog.height()) / 2), "border-radius":"3px"}).fadeTo(1, dialog.DIG_ALPHA.BODY);
                break;
            case dialog.DIG_STYLE.DOING:
                dialog.$doing.show().html(content);
                dialog.$pop.hide();
                dialog.$body.hide();
                dialog.$dialog.css({"left":((zmnPage.winWidth - dialog.$dialog.width()) / 2), "top":((zmnPage.winHeight - dialog.$dialog.height()) / 2), "border-radius":"3px"}).fadeTo(1, dialog.DIG_ALPHA.BODY);
                break;
            default :
                dialog.$pop.show().html(content);
                dialog.$body.hide();
                dialog.$doing.hide();
                dialog.$dialog.css({"left":((zmnPage.winWidth - dialog.$dialog.width()) / 2), "top":((zmnPage.winHeight - dialog.$dialog.height()) / 2), "border-radius":"3px"}).fadeTo(1, dialog.DIG_ALPHA.POP);
                //if(dialog.digWidth - dialog.$dialog.outerWidth() < 50) { dialog.$dialog.width(dialog.digWidth - 50); }
                break;
        }

        if(dialog.mode){
            dialog.$pdmodel.width(zmnPage.winWidth).height(zmnPage.docHeight);
            dialog.$pdmodel.show().css({"left":0, "top":0}).fadeTo(100, dialog.DIG_ALPHA.MODEL);
        }
        $("select").css("visibility","hidden");
    },
    load: function(title, content, showHeader, options) {	//兼容以前版本
        dialog.mode = true;
        dialog.style = dialog.DIG_STYLE.MUI;
        dialog.init(title, content, showHeader, options);
    },
    pop: function(content, fail, callback) {
        var cssName = fail == true ? "" : "fail";
        dialog.mode = true;
        dialog.style = dialog.DIG_STYLE.POP;
        dialog.init("", "<span class='icon icon-pop " + cssName + "'></span><span class='text " + cssName + "'>" + content + "</span>");
        dialog.close(2000, callback);
    },
    done: function(content) {	//处理完成
        dialog.pop(content, true);
    },
    doing: function(content) {	//处理中
        content = typeof content == "undefined" ? "正在处理，请稍后…" : content;
        dialog.mode = true;
        dialog.style = dialog.DIG_STYLE.DOING;
        dialog.init("", "<span class='doing-box'><span class='doing doing-1'></span><span class='doing doing-2'></span><span class='doing doing-3'></span></span><span class='text'>" + content + "</span>");
        //dialog.$dialog.css("left", (zmnPage.winWidth - dialog.$dialog.width()) / 2 );
    },
    loading: function() {	//加载中
        dialog.doing("正在加载，请稍后…");
    },


    top: function(top){
        dialog.$dialog.css({"top": top, "bottom": ""});
    },
    width: function(reduceWidth, margin) {
        dialog.$dialog.width(dialog.digWidth - reduceWidth);
        dialog.$dialog.css("left", Math.floor(reduceWidth/2));
        margin = typeof margin == "undefined" ? 0 : margin;
        if(margin > 0) { dialog.$dialog.css({"margin-left": margin, "margin-right": margin}); }
    },
    reset: function(){
        var headerHeight = $(dialog.$header).height();
        var docHeight = $(window).height();
        if(dialog.$body.height() > docHeight - headerHeight) {
            dialog.$dialog.height(docHeight - 20 );
            dialog.$body.height(docHeight - headerHeight - 40);
            var $ul = dialog.$body.find("ul");
            $ul.width($ul.width() - 20);
            dialog.$body.css("overflow", "auto");
        }
    },
    direct: function(url,timeout){
        if(typeof timeout == "undefined" ){ timeout = 0; }
        setTimeout(function(){
            if(typeof url == "undefined"){url=location.href;}
            window.location = url;
        },timeout);
    },
    show: function(){
        dialog.$dialog.show();
        if(dialog.mode){ dialog.$pdmodel.show();}
    },
    close: function(timeout, callBack) {	//关闭延迟毫秒
        if(typeof timeout == "undefined" ){ timeout = 0; }
        setTimeout(function(){
            if(dialog.$dialog) { dialog.$dialog.hide(); }
            dialog.$pdmodel.hide();
            $("select").css("visibility","visible");
            if(!omsUtil.isNull(callBack)){ callBack(); } else {
                if(dialog.refresh) { location.reload(); }
            }

        }, timeout);
    }
};	//dialog end


//遮罩层及自定义POP弹窗
var maskPg = {
    $container: "",
    maskAlpha: 0.85,
    animeType: {"scaleLeftTop": 10, "scaleLeftBottom": 11, "scaleRightTop": 12, "scaleRightBottom": 13, "moveUp": 20, "moveDown": 21, "fade": 31},
    init: function(){
        dialog.$pdmodel = $(dialog.pdmodelSelecter);
        dialog.$pdmodel.width(zmnPage.winWidth).height(zmnPage.docHeight);
        dialog.$pdmodel.css({"left":0, "top":0}).fadeTo(100, maskPg.maskAlpha);
        $("select").css("visibility","hidden");
    },
    loadCustomPOP: function(options){
        var ctrWidth = $(maskPg.$container).width();
        var ctrHeight = $(maskPg.$container).height();
        var offsetTop = Math.floor((zmnPage.winHeight - ctrHeight) / 2);
        var offsetLeft = Math.floor((zmnPage.winWidth - ctrWidth) / 2);

        if(omsUtil.isNotNull(options)) {
            var speed = omsUtil.isEmptyNull(options[1]) ? 100 : options[1];
            switch(options[0]) {
                case maskPg.animeType.scaleLeftTop:
                    $(maskPg.$container).css({"top": 0, "left": 0, "width": 0, "height": 0}).animate({"top": offsetTop, "left": offsetLeft, width: ctrWidth, height: ctrHeight, opacity: "show"}, speed);
                    break;
                case maskPg.animeType.scaleLeftBottom:
                    $(maskPg.$container).css({"top": zmnPage.winHeight, "left": 0, "width": 0, "height": 0}).animate({"top": offsetTop, "left": offsetLeft, width: ctrWidth, height: ctrHeight, opacity: "show"}, speed);
                    break;
                case maskPg.animeType.scaleRightTop:
                    $(maskPg.$container).css({"top": 0, "left": zmnPage.winWidth, "width": 0, "height": 0}).animate({"top": offsetTop, "left": offsetLeft, width: ctrWidth, height: ctrHeight, opacity: "show"}, speed);
                    break;
                case maskPg.animeType.scaleRightBottom:
                    $(maskPg.$container).css({"top": zmnPage.winHeight, "left": zmnPage.winWidth, "width": 0, "height": 0}).animate({"top": offsetTop, "left": offsetLeft, width: ctrWidth, height: ctrHeight, opacity: "show"}, speed);
                    break;
                case maskPg.animeType.moveUp:
                    $(maskPg.$container).css({"top": zmnPage.winHeight, "left": offsetLeft}).animate({top: offsetTop, opacity: "show"}, speed);
                    break;
                case maskPg.animeType.moveDown:
                    $(maskPg.$container).css({"top": -ctrHeight, "left": offsetLeft}).animate({top: offsetTop, opacity: "show"}, speed);
                    break;
                default :
                    $(maskPg.$container).css({"top": offsetTop, "left": offsetLeft}).fadeIn(speed);
                    break;
            }
        }else {
            $(maskPg.$container).css({"top": offsetTop, "left": offsetLeft}).fadeIn(speed);
        }

    },
    close: function(callBack){
        $(maskPg.$container).hide();
        if(!omsUtil.isNull(callBack)) { callBack(); }
    }
};


var zmnPage = {
    $toTop: null,
    docHeight: 0,       //网页高度
    winWidth: 0,        //窗口宽度
    winHeight: 0,       //窗口高度
    isIndex: false,
    init: function () {
        zmnPage.docHeight = omsUtil.docHeight();
        zmnPage.winWidth = omsUtil.winWidth();
        zmnPage.winHeight = omsUtil.winHeight();

        $(document.body).append('<div id="pdmodel" class="ui-pdmodel"></div><div id="dialog" class="ui-dialog"></div>');
        if ($(document).find("#pdmodel").length > 0) {
            $("#pdmodel").bind("click", function () {
                dialog.close();
                maskPg.close();
            });
        }

        //回到顶部
        zmnPage.$toTop = $(".ui-top");
        if (zmnPage.$toTop.length > 0) {
            zmnPage.$toTop.bind("click", function () {
                zmnPage.toTop();
            });
            window.onscroll = function () {
                zmnPage.toggleToTop();
            }
        }
    },
    toggleToTop: function(){
        var scrolltop = document.documentElement.scrollTop || document.body.scrollTop;
        if (scrolltop > 300) {
            if (zmnPage.$toTop.css('display') == "none") {
                zmnPage.$toTop.show();
            }
        } else {
            if (zmnPage.$toTop.css('display') == "block") {
                zmnPage.$toTop.hide();
            }
        }
    },
    //回到顶部
    toTop: function () {
        document.documentElement.scrollTop = document.body.scrollTop = 0;
    },
    //跳转到登录页
    directLogin: function () {
        var url = constant.URL_PASSPORT_PREFIX + "?jumpurl=" + location.href;
        omsUtil.direct(url);
    },
    //检查登录
    checkLogin: function (isDirect) {  //是否转向
        var cookieUser = cookie.get(constant.COOKIE_USER);
        if (omsUtil.isEmptyNull(cookieUser)) {
            if (isDirect) { zmnPage.directLogin(); }
            return false;
        } else {
            return true;
        }
    },
    //下拉页面时头部透明
    headerFade: {
        $header: null,
        headerHeight: 44,   //header高度
        headerAlpha: 0.5,   //透明度
        isFade: false,      //是否已透明
        load: function(){
            zmnPage.headerFade.$header = $(".header-base");
            if(zmnPage.headerFade.$header.length == 0) { return; }
            //zmnPage.headerFade.headerHeight = zmnPage.headerFade.$header.height();
            window.onscroll = function () {
                var scrolltop = document.documentElement.scrollTop || document.body.scrollTop;
                if (scrolltop > zmnPage.headerFade.headerHeight) {
                    if(!zmnPage.headerFade.isFade) {
                        zmnPage.headerFade.$header.fadeTo(100, zmnPage.headerFade.headerAlpha);
                        zmnPage.headerFade.isFade = true;
                    }
                } else {
                    if(zmnPage.headerFade.isFade) {
                        zmnPage.headerFade.$header.fadeTo(100, 1);
                        zmnPage.headerFade.isFade = false;
                    }
                }
                zmnPage.toggleToTop();
            }
        }
    }
};


try {

    /**********自定义Checkbox/Radio样式 begin**********/
//type normal正常 littlei小行距，默认正常
    $.fn.customRadio = function(isWrap, cssName){
        if(omsUtil.isNull(isWrap)) { isWrap = true; }
        if(omsUtil.isEmptyNull(cssName)) { cssName = "ui-radio"; }
        var cssChecked = "checked";
        $(this).each(function(i){
            if($(this).is('[type=radio]')){
                var $input = $(this);
                var $label = $("label[for=" + $input.attr("id") + "]");
                if(isWrap) { $('<span class="' + cssName + '"></span>').insertBefore($input).append($input,$label); }
                var $checkBox = $input.parent();
                var $radios = $('input[name='+$input.attr('name')+']');
                $input.hide();
                $checkBox.bind('updateState',function(){
                    if($input.is(':checked')){
                        if($input.is(':radio')){ $radios.each(function(){ $(this).parent().removeClass(cssChecked); }); };
                        $checkBox.addClass(cssChecked);
                    } else { $checkBox.removeClass(cssChecked); }
                })
                    .trigger('updateState')
                    .click(function(){ $checkBox.trigger('updateState'); })
            }
        });
    };
    $.fn.customCheckbox = function(isWrap, cssName){
        if(omsUtil.isNull(isWrap)) { isWrap = true; }
        if(omsUtil.isEmptyNull(cssName)) { cssName = "ui-chkbox"; }
        var cssChecked = "checked";
        $(this).each(function(i){
            if($(this).is('[type=checkbox]')){
                var $input = $(this);
                var $label = $("label[for=" + $input.attr("id") + "]");
                if(isWrap) { $('<span class="' + cssName + '"></span>').insertBefore($input).append($input,$label); }
                var $checkBox = $input.parent();
                $input.hide();
                $checkBox.bind('updateState',function(){
                    if($input.is(':checked')){ $checkBox.addClass(cssChecked); } else { $checkBox.removeClass(cssChecked); }
                })
                    .trigger('updateState')
                    .click(function(){ $checkBox.trigger('updateState'); })
            }
        });
    };
//$(document).ready(function(){ $('input').customCheckbox(); });

    /**********自定义Checkbox/Radio样式 end**********/



    /**********jQuery扩展 begin**********/
    $.fn.extend({

        //控制图片的最大宽度，并按比例缩小显示
        widthMax: function(width)	{
            this.each(function(i){
                var $this = $(this);
                if($this.width() > width ){ $this.height(width/($this.width()/$this.height())); $this.width(width); }
            });
        },

        //显示最大宽度和高度，并按比例缩小显示
        max: function(width,height){
            this.each(function(i){
                var $this = $(this);
                if($this.width() > width ){
                    if($this.width()/$this.height() > width/height){
                        if($this.width() > width) { $this.width(width); }
                        if($this.height() > height) { $this.height(height); }
                    }
                    else{
                        if($this.height() > height) { $this.height(height); }
                        if($this.width() > width) { $this.width(width); }
                    }}});
        },

        //文本框内提示文字根据内容显示或隐藏
        inputTextDes: function(desText) {
            $(this).bind("click", function(){ var text = $(this).val().trim(); if(text == desText){ $(this).val(""); } });
            $(this).bind("blur", function(){ var text = $(this).val().trim(); if(text == ""){ $(this).val(desText); } });
        },

        //显示/隐藏
        //contSelector 要显示或隐藏的jQuery选择器表达式
        showShift: function (contSelector){
            $(this).css("cursor","pointer").click(function(){
                if($(contSelector).css("display") == "block")
                    $(this).attr("src",utils.theme+"images/icon_close.gif");
                else
                    $(this).attr("src",utils.theme+"images/icon_show.gif");
                $(contSelector).toggle();
            });
        },

        //绑定数据到下拉框
        //json 要绑定的数据，json格式
        //valueoption 要绑定的value名称
        //textoption 要绑定的text名称
        //defaultText 首项文本
        //selectedValue 设置默认选中的值（value/text）
        bindSelect: function (json, valueoption, textoption, defaultText, selectedValue){
            if(typeof selectedValue == "undefined"){ selectedValue = ""; }
            var $this = $(this);
            $this.html("<option value=\"0\">"+defaultText+"</option>");   //清空
            $.each(json, function(i){
                if(json[i][valueoption] == selectedValue || json[i][textoption] == selectedValue )
                    $this.append("<option value=\""+json[i][valueoption]+"\" selected>"+json[i][textoption]+"</option>");
                else
                    $this.append("<option value=\""+json[i][valueoption]+"\">"+json[i][textoption]+"</option>");
            });
        },

        //设置下拉框的默认选中（模糊匹配）
        //selectedType 默认选中参数 1为value，2为text
        //selectedValue 设置默认选中的值（value/text）
        defaultSelected: function (selectedType, selectedValue){
            var options = $(this).children();
            var regx = new RegExp(selectedValue,"ig");
            for(var i=0;i<options.length;i++){
                if(regx.test(selectedType==1?options[i].value:options[i].text)) { $(this).get(0).selectedIndex=i; break; }
            }
        },

        //设置单选默认选中
        //checkedValue 设置默认选中的值（value/text）
        defaultChecked: function (checkedValue){
            var $this = $(this);
            $this.each(function(i){
                if($this.get(i).value==checkedValue){ $this.get(i).checked=true; }
            });
        },

        //指定位置显示浮动层
        //panel要显示的层 action鼠标动作 mouse/load/focus options基点（左上角）偏移位置定义，如{x:10, y:20}
        layer: function(panel,action,options){
            if(typeof type == "undefined"){ action = "mouse"; }
            if(typeof options == "undefined"){ options = {x:0, y:0} }
            //$(this).css({cursor:"pointer"});
            $(panel).css({"z-index":"80", position:"absolute"}).css({left:$(this).offset().left+options.x, top:$(this).offset().top+options.y});
            switch(action){
                case "load": $(panel).show(); break;
                case "mouse": $(this).mouseover(function(){$(panel).show();}).mouseout(function(){$(panel).hide();}); break;
                case "focus": $(this).focus(function(){$(panel).show();}).mouseout(function(){$(panel).hide();}); break;
                default: $(this).click(function(){$(panel).show();}).mouseout(function(){$(panel).hide();}); break;
            }
            if(action != "load") { $(panel).mouseover(function(){$(panel).show();}).mouseout(function(){$(panel).hide();});}
        },

        //实时提示输入字符数
        //可输入的最多字符数，1个全角字符等于2个半角字符
        //已输入字符数提示的容器
        inputChars: function (max, showHolder){
            var value = $(this).val().trim().replace(/[^\x00-\xff]/g, "**");
            while(value.length>max*2){
                $(this).val( $(this).val().substring (0, $(this).val().length-1 ) );
                value = $(this).val().trim().replace(/[^\x00-\xff]/g, "**");
            }
            $(showHolder).text( Math.round(value.length/2) );
        },

        //简繁显示效果切换
        //cssName 当前项效果样式
        slideDown: function(cssName) {
            var $this = $(this);
            $this.each(function(){
                var $$this = $(this);
                $$this.bind("mouseover", function(){
                    $this.removeClass(cssName);
                    $$this.addClass(cssName);
                });
            });
        },

        //tab 切换
        //contSelecter 内容块选择器
        //tabCssName 当前tab效果样式
        slideTab: function(contSelecter, tabCssName){
            var $this = $(this);
            $this.each(function(i){
                var $$this = $(this);
                $$this.bind("click", function(){
                    $this.removeClass(tabCssName);
                    $$this.addClass(tabCssName);
                    if(!omsUtil.isEmptyNull(contSelecter)) { $(contSelecter).hide().eq(i).show();}
                });
            });
        },

    });	//jQuery.fn.extend end

    /**********jQuery扩展 end**********/



    $.extend({
        //改写的装载javascript
        getJS: function(url, callback) { $.ajax({ type:"GET", url:url, dataType:"script", async:false, cache:true, success:callback }); }
    });	//jQuery.extend end
} catch (e) {
}

/* !art-template v3.0.3 - Template Engine | http://aui.github.com/artTemplate/ */
!function(){function a(a){return a.replace(t,"").replace(u,",").replace(v,"").replace(w,"").replace(x,"").split(y)}function b(a){return"'"+a.replace(/('|\\)/g,"\\$1").replace(/\r/g,"\\r").replace(/\n/g,"\\n")+"'"}function c(c,d){function e(a){return m+=a.split(/\n/).length-1,k&&(a=a.replace(/\s+/g," ").replace(/<!--[\w\W]*?-->/g,"")),a&&(a=s[1]+b(a)+s[2]+"\n"),a}function f(b){var c=m;if(j?b=j(b,d):g&&(b=b.replace(/\n/g,function(){return m++,"$line="+m+";"})),0===b.indexOf("=")){var e=l&&!/^=[=#]/.test(b);if(b=b.replace(/^=[=#]?|[\s;]*$/g,""),e){var f=b.replace(/\s*\([^\)]+\)/,"");n[f]||/^(include|print)$/.test(f)||(b="$escape("+b+")")}else b="$string("+b+")";b=s[1]+b+s[2]}return g&&(b="$line="+c+";"+b),r(a(b),function(a){if(a&&!p[a]){var b;b="print"===a?u:"include"===a?v:n[a]?"$utils."+a:o[a]?"$helpers."+a:"$data."+a,w+=a+"="+b+",",p[a]=!0}}),b+"\n"}var g=d.debug,h=d.openTag,i=d.closeTag,j=d.parser,k=d.compress,l=d.escape,m=1,p={$data:1,$filename:1,$utils:1,$helpers:1,$out:1,$line:1},q="".trim,s=q?["$out='';","$out+=",";","$out"]:["$out=[];","$out.push(",");","$out.join('')"],t=q?"$out+=text;return $out;":"$out.push(text);",u="function(){var text=''.concat.apply('',arguments);"+t+"}",v="function(filename,data){data=data||$data;var text=$utils.$include(filename,data,$filename);"+t+"}",w="'use strict';var $utils=this,$helpers=$utils.$helpers,"+(g?"$line=0,":""),x=s[0],y="return new String("+s[3]+");";r(c.split(h),function(a){a=a.split(i);var b=a[0],c=a[1];1===a.length?x+=e(b):(x+=f(b),c&&(x+=e(c)))});var z=w+x+y;g&&(z="try{"+z+"}catch(e){throw {filename:$filename,name:'Render Error',message:e.message,line:$line,source:"+b(c)+".split(/\\n/)[$line-1].replace(/^\\s+/,'')};}");try{var A=new Function("$data","$filename",z);return A.prototype=n,A}catch(B){throw B.temp="function anonymous($data,$filename) {"+z+"}",B}}var d=function(a,b){return"string"==typeof b?q(b,{filename:a}):g(a,b)};d.version="3.0.0",d.config=function(a,b){e[a]=b};var e=d.defaults={openTag:"<%",closeTag:"%>",escape:!0,cache:!0,compress:!1,parser:null},f=d.cache={};d.render=function(a,b){return q(a,b)};var g=d.renderFile=function(a,b){var c=d.get(a)||p({filename:a,name:"Render Error",message:"Template not found"});return b?c(b):c};d.get=function(a){var b;if(f[a])b=f[a];else if("object"==typeof document){var c=document.getElementById(a);if(c){var d=(c.value||c.innerHTML).replace(/^\s*|\s*$/g,"");b=q(d,{filename:a})}}return b};var h=function(a,b){return"string"!=typeof a&&(b=typeof a,"number"===b?a+="":a="function"===b?h(a.call(a)):""),a},i={"<":"&#60;",">":"&#62;",'"':"&#34;","'":"&#39;","&":"&#38;"},j=function(a){return i[a]},k=function(a){return h(a).replace(/&(?![\w#]+;)|[<>"']/g,j)},l=Array.isArray||function(a){return"[object Array]"==={}.toString.call(a)},m=function(a,b){var c,d;if(l(a))for(c=0,d=a.length;d>c;c++)b.call(a,a[c],c,a);else for(c in a)b.call(a,a[c],c)},n=d.utils={$helpers:{},$include:g,$string:h,$escape:k,$each:m};d.helper=function(a,b){o[a]=b};var o=d.helpers=n.$helpers;d.onerror=function(a){var b="Template Error\n\n";for(var c in a)b+="<"+c+">\n"+a[c]+"\n\n";"object"==typeof console&&console.error(b)};var p=function(a){return d.onerror(a),function(){return"{Template Error}"}},q=d.compile=function(a,b){function d(c){try{return new i(c,h)+""}catch(d){return b.debug?p(d)():(b.debug=!0,q(a,b)(c))}}b=b||{};for(var g in e)void 0===b[g]&&(b[g]=e[g]);var h=b.filename;try{var i=c(a,b)}catch(j){return j.filename=h||"anonymous",j.name="Syntax Error",p(j)}return d.prototype=i.prototype,d.toString=function(){return i.toString()},h&&b.cache&&(f[h]=d),d},r=n.$each,s="break,case,catch,continue,debugger,default,delete,do,else,false,finally,for,function,if,in,instanceof,new,null,return,switch,this,throw,true,try,typeof,var,void,while,with,abstract,boolean,byte,char,class,const,double,enum,export,extends,final,float,goto,implements,import,int,interface,long,native,package,private,protected,public,short,static,super,synchronized,throws,transient,volatile,arguments,let,yield,undefined",t=/\/\*[\w\W]*?\*\/|\/\/[^\n]*\n|\/\/[^\n]*$|"(?:[^"\\]|\\[\w\W])*"|'(?:[^'\\]|\\[\w\W])*'|\s*\.\s*[$\w\.]+/g,u=/[^\w$]+/g,v=new RegExp(["\\b"+s.replace(/,/g,"\\b|\\b")+"\\b"].join("|"),"g"),w=/^\d[^,]*|,\d[^,]*/g,x=/^,+|,+$/g,y=/^$|,+/;e.openTag="{{",e.closeTag="}}";var z=function(a,b){var c=b.split(":"),d=c.shift(),e=c.join(":")||"";return e&&(e=", "+e),"$helpers."+d+"("+a+e+")"};e.parser=function(a){a=a.replace(/^\s/,"");var b=a.split(" "),c=b.shift(),e=b.join(" ");switch(c){case"if":a="if("+e+"){";break;case"else":b="if"===b.shift()?" if("+b.join(" ")+")":"",a="}else"+b+"{";break;case"/if":a="}";break;case"each":var f=b[0]||"$data",g=b[1]||"as",h=b[2]||"$value",i=b[3]||"$index",j=h+","+i;"as"!==g&&(f="[]"),a="$each("+f+",function("+j+"){";break;case"/each":a="});";break;case"echo":a="print("+e+");";break;case"print":case"include":a=c+"("+b.join(",")+");";break;default:if(/^\s*\|\s*[\w\$]/.test(e)){var k=!0;0===a.indexOf("#")&&(a=a.substr(1),k=!1);for(var l=0,m=a.split("|"),n=m.length,o=m[l++];n>l;l++)o=z(o,m[l]);a=(k?"=":"=#")+o}else a=d.helpers[c]?"=#"+c+"("+b.join(",")+");":"="+a}return a},"function"==typeof define?define(function(){return d}):"undefined"!=typeof exports?module.exports=d:this.template=d}();


/* !touchSlide v1.1 Copyright 2013 大话主席 */
var touchSlide=function(a){a=a||{};var b={slideCell:a.slideCell||"#touchSlide",titCell:a.titCell||".hd li",mainCell:a.mainCell||".bd",effect:a.effect||"left",autoPlay:a.autoPlay||!1,delayTime:a.delayTime||200,interTime:a.interTime||2500,defaultIndex:a.defaultIndex||0,titOnClassName:a.titOnClassName||"on",autoPage:a.autoPage||!1,prevCell:a.prevCell||".prev",nextCell:a.nextCell||".next",pageStateCell:a.pageStateCell||".pageState",pnLoop:"undefined "==a.pnLoop?!0:a.pnLoop,startFun:a.startFun||null,endFun:a.endFun||null,switchLoad:a.switchLoad||null},c=document.getElementById(b.slideCell.replace("#",""));if(!c)return!1;var d=function(a,b){a=a.split(" ");var c=[];b=b||document;var d=[b];for(var e in a)0!=a[e].length&&c.push(a[e]);for(var e in c){if(0==d.length)return!1;var f=[];for(var g in d)if("#"==c[e][0])f.push(document.getElementById(c[e].replace("#","")));else if("."==c[e][0])for(var h=d[g].getElementsByTagName("*"),i=0;i<h.length;i++){var j=h[i].className;j&&-1!=j.search(new RegExp("\\b"+c[e].replace(".","")+"\\b"))&&f.push(h[i])}else for(var h=d[g].getElementsByTagName(c[e]),i=0;i<h.length;i++)f.push(h[i]);d=f}return 0==d.length||d[0]==b?!1:d},e=function(a,b){var c=document.createElement("div");c.innerHTML=b,c=c.children[0];var d=a.cloneNode(!0);return c.appendChild(d),a.parentNode.replaceChild(c,a),m=d,c},g=function(a,b){!a||!b||a.className&&-1!=a.className.search(new RegExp("\\b"+b+"\\b"))||(a.className+=(a.className?" ":"")+b)},h=function(a,b){!a||!b||a.className&&-1==a.className.search(new RegExp("\\b"+b+"\\b"))||(a.className=a.className.replace(new RegExp("\\s*\\b"+b+"\\b","g"),""))},i=b.effect,j=d(b.prevCell,c)[0],k=d(b.nextCell,c)[0],l=d(b.pageStateCell)[0],m=d(b.mainCell,c)[0];if(!m)return!1;var N,O,n=m.children.length,o=d(b.titCell,c),p=o?o.length:n,q=b.switchLoad,r=parseInt(b.defaultIndex),s=parseInt(b.delayTime),t=parseInt(b.interTime),u="false"==b.autoPlay||0==b.autoPlay?!1:!0,v="false"==b.autoPage||0==b.autoPage?!1:!0,w="false"==b.pnLoop||0==b.pnLoop?!1:!0,x=r,y=null,z=null,A=null,B=0,C=0,D=0,E=0,G=/hp-tablet/gi.test(navigator.appVersion),H="ontouchstart"in window&&!G,I=H?"touchstart":"mousedown",J=H?"touchmove":"",K=H?"touchend":"mouseup",M=m.parentNode.clientWidth,P=n;if(0==p&&(p=n),v){p=n,o=o[0],o.innerHTML="";var Q="";if(1==b.autoPage||"true"==b.autoPage)for(var R=0;p>R;R++)Q+="<li>"+(R+1)+"</li>";else for(var R=0;p>R;R++)Q+=b.autoPage.replace("$",R+1);o.innerHTML=Q,o=o.children}"leftLoop"==i&&(P+=2,m.appendChild(m.children[0].cloneNode(!0)),m.insertBefore(m.children[n-1].cloneNode(!0),m.children[0])),N=e(m,'<div class="tempWrap" style="overflow:hidden; position:relative;"></div>'),m.style.cssText="width:"+P*M+"px;"+"position:relative;overflow:hidden;padding:0;margin:0;";for(var R=0;P>R;R++)m.children[R].style.cssText="display:table-cell;vertical-align:top;width:"+M+"px";var S=function(){"function"==typeof b.startFun&&b.startFun(r,p)},T=function(){"function"==typeof b.endFun&&b.endFun(r,p)},U=function(a){var b=("leftLoop"==i?r+1:r)+a,c=function(a){for(var b=m.children[a].getElementsByTagName("img"),c=0;c<b.length;c++)b[c].getAttribute(q)&&(b[c].setAttribute("src",b[c].getAttribute(q)),b[c].removeAttribute(q))};if(c(b),"leftLoop"==i)switch(b){case 0:c(n);break;case 1:c(n+1);break;case n:c(0);break;case n+1:c(1)}},V=function(){M=N.clientWidth,m.style.width=P*M+"px";for(var a=0;P>a;a++)m.children[a].style.width=M+"px";var b="leftLoop"==i?r+1:r;W(-b*M,0)};window.addEventListener("resize",V,!1);var W=function(a,b,c){c=c?c.style:m.style,c.webkitTransitionDuration=c.MozTransitionDuration=c.msTransitionDuration=c.OTransitionDuration=c.transitionDuration=b+"ms",c.webkitTransform="translate("+a+"px,0)"+"translateZ(0)",c.msTransform=c.MozTransform=c.OTransform="translateX("+a+"px)"},X=function(a){switch(i){case"left":r>=p?r=a?r-1:0:0>r&&(r=a?0:p-1),null!=q&&U(0),W(-r*M,s),x=r;break;case"leftLoop":null!=q&&U(0),W(-(r+1)*M,s),-1==r?(z=setTimeout(function(){W(-p*M,0)},s),r=p-1):r==p&&(z=setTimeout(function(){W(-M,0)},s),r=0),x=r}S(),A=setTimeout(function(){T()},s);for(var c=0;p>c;c++)h(o[c],b.titOnClassName),c==r&&g(o[c],b.titOnClassName);0==w&&(h(k,"nextStop"),h(j,"prevStop"),0==r?g(j,"prevStop"):r==p-1&&g(k,"nextStop")),l&&(l.innerHTML="<span>"+(r+1)+"</span>/"+p)};if(X(),u&&(y=setInterval(function(){r++,X()},t)),o)for(var R=0;p>R;R++)!function(){var a=R;o[a].addEventListener("click",function(){clearTimeout(z),clearTimeout(A),r=a,X()})}();k&&k.addEventListener("click",function(){(1==w||r!=p-1)&&(clearTimeout(z),clearTimeout(A),r++,X())}),j&&j.addEventListener("click",function(){(1==w||0!=r)&&(clearTimeout(z),clearTimeout(A),r--,X())});var Y=function(a){clearTimeout(z),clearTimeout(A),O=void 0,D=0;var b=H?a.touches[0]:a;B=b.pageX,C=b.pageY,m.addEventListener(J,Z,!1),m.addEventListener(K,$,!1)},Z=function(a){if(!H||!(a.touches.length>1||a.scale&&1!==a.scale)){var b=H?a.touches[0]:a;if(D=b.pageX-B,E=b.pageY-C,"undefined"==typeof O&&(O=!!(O||Math.abs(D)<Math.abs(E))),!O){switch(a.preventDefault(),u&&clearInterval(y),i){case"left":(0==r&&D>0||r>=p-1&&0>D)&&(D=.4*D),W(-r*M+D,0);break;case"leftLoop":W(-(r+1)*M+D,0)}null!=q&&Math.abs(D)>M/3&&U(D>-0?-1:1)}}},$=function(a){0!=D&&(a.preventDefault(),O||(Math.abs(D)>M/10&&(D>0?r--:r++),X(!0),u&&(y=setInterval(function(){r++,X()},t))),m.removeEventListener(J,Z,!1),m.removeEventListener(K,$,!1))};m.addEventListener(I,Y,!1)};